#!/usr/bin/python
# -*- coding: UTF-8 -*-

import random
import time

class PlayCard():
    """
    定义类，实现生成一副顺序扑克牌的方法及一副随机扑克牌的方法(啊哈哈哈哈哈哈哈)
    """
    def __init__(self):
        """
        属性定义
        """
        self.start_numbers=2
        self.end_numbers=11
        self.types = ['♥', '♠', '♦', '♣']
        self.JQK = ['J', 'Q', 'K']
        self.A = 'A'
        self.play_cards = []
        self.play_cards_random = []
        self.play_card()
    def play_card(self):
        """
        生成一副顺序扑克牌
        :return:
        """
        for type in self.types:
            self.play_cards.append(type+self.A)
            for num in range(self.start_numbers,self.end_numbers):
                self.play_cards.append(type+str(num))
            for JJQQKK in self.JQK:
                self.play_cards.append(type+JJQQKK)
        self.play_cards.append('王大')
        self.play_cards.append('王小')
        return self.play_cards
    def random_play_card(self):
            """
            生成一副随机扑克牌
            :return:
            """
            number_1 = 54
            while number_1 >0:
                number_1-=1
                a = int(random.randint(0, number_1))
                self.play_cards_random.append( self.play_cards[a])
                del self.play_cards[a]

            return self.play_cards_random

    def random_one_card(self):
        """
        随机取一张牌
        :return:
        """
        a=int(random.randint(0,53))
        return self.play_cards[a]

    def color(self):
        """
        打印带颜色的红桃和方片
        :return:
        """
        b=int(random.randint(0,53))
        x=self.play_cards[b]
        if x[:1] in ['♥','♦']:
            return ('\033[36;31m{0}\033[1;37;37m'.format(x))
        else:
            return self.play_cards[b]
    
    def __getitem__(self, item):
        """
        实现getitem方法，通过索引直接取一张牌
        :param item:
        :return:
        """
        return self.play_cards[item]


a = PlayCard()#对类进行实例化
print("打印一副顺序的牌")
print("指定取出第几张牌：" + a[2])
print("查看是否实现了颜色展示：" + a.color())
print("随机取一张牌：" + a.random_one_card())
print("打印顺序的一副牌")
print(a.play_cards)
print("打印随机的一副牌")
print(a.random_play_card())




